<?php
namespace mi\controllers;

use frontend\models\SmsCodeModel;
use Yii;
use yii\data\Pagination; //分页
use mi\base\BaseController;
use frontend\utils\UrlUtil;
use frontend\utils\CurlUtil;

/**
 * Site controller
 */
class YumiController extends BaseController
{
    public $defaultAction = 'list';

    /**
     * 欢迎页
     * @return string
     */
    public function actionIndex()
    {
        $url = '/img/logo/'; //图片所存在的目录
//        $hostdir = dirname(__FILE__).'/../web'.$url; //要读取的文件夹
        $hostdir = Yii::$app->basePath.'/web'.$url;
//        $hostdir = $_SERVER['DOCUMENT_ROOT'].$url;
        $filesnames = scandir($hostdir); //得到所有的文件
        $yumi = [];
        foreach ($filesnames as $k=>$name) {
            if(strlen($name) >2){
                $yumi[$k]['url'] = $url.$name;
                $name = explode('.',$name);
                $yumi[$k]['name'] = $name[0].'.'.$name[1];
            }
        }
        //数组组装
        $yumi = $this->getResult($yumi);
        return $this->render('index',[
            'dai'=>$yumi,
        ]);
    }

    public function getResult($yu)
    {
        $yu = array_values($yu);
        $limit = 10;
        $count = floor(count($yu)/$limit);
        $result = [];
        for ($i = 0; $i <= $count; $i++){
            $star = $i*$limit;
            $result[$i] = array_slice($yu,$star,$limit);
        }
        return $result;
    }

    public function actionList()
    {
        Yii::$app->layout = false;
        $pinyin = Yii::$app->params['pinyin'];
        $number = Yii::$app->params['number'];
        $yingwen = Yii::$app->params['yingwen'];
        $feizhuliu = Yii::$app->params['feizhuliu'];
        $yishou = Yii::$app->params['yishou'];
        return $this->render('list',[
            'number'=>$number,
            'pinyin'=>$pinyin,
            'yingwen'=>$yingwen,
            'feizhuliu'=>$feizhuliu,
            'yishou'=>$yishou,
        ]);
    }
}

